import { Focus, Goods } from '../../store/index.js';
const focus = new Focus();
const goods = new Goods();
Page({
  
  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: getApp().globalData.imgUrl,
    page: {},
    star: {
     value: 5
    },
    imgUrls: [
      'http://deking008.gitee.io/zpimg/wximg/banner.png',
      'http://deking008.gitee.io/zpimg/wximg/banner2.png',
      'http://deking008.gitee.io/zpimg/wximg/banner.png'
    ],
    productList: [],
    swiper: [],
    indicatorDots: true,
    indicatorColor:"#999",
    indicatorActivecolor:"#fa5c55",
    autoplay: true,
    interval: 3000,
    duration: 800,
    speed:5,
    swiperNum:5
  },
  goSearch: function(){
    wx.navigateTo({
      url: '/pages/search/search',
    })
  },
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },
  getFoucs: function() {
    focus.getFocus((res) => {
      this.setData({
        swiper:res.result.data
      });
    }, this.data.swiperNum);
  },
  getRecommend: function() {
   
    let that = this;
    goods.getRecommend((res)=>{
      this.setData({
        productList: res.result.data
      });
    },this.data.speed)
  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.dataInit();
  
  },

  dataInit () {
    this.getFoucs();
    this.getRecommend();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})